UserHandler1 … UserHandler5 handlers

Description
UserHandler1 through UserHandler5 are five handlers you can use as subroutines—containers for common code used by more than one button. In cases where you write a single group of statements that needs to be included in several different buttons, instead of repeating the statements in each button, you can place the statements in a UserHandler in one button and have the other buttons Call that handler.

Examples
Call UserHandler1, "Common" // Executes statements in UserHandler1 on button “Common”

// This script is in a button named “Routines”
On UserHandler4
     // This is an error-handling subroutine that plays the sound named in g_theErrSound,
     // displays the error text in a message box, and appends the error text and the time
     // the error occurred to a log file whose path is in g_theErrLog. 
     // When the handler is finished, it returns to the script that called it.
     Variable Global g_theErrSound, g_theErrMessage, g_theErrLog
     Sound g_theErrSound
     Message g_theErrMessage
     If g_theErrLog      // path of error log (a text file)
          File(g_theErrLog).Append = (Time 1) & " " & g_theErrMessage & Return
     End If 
End UserHandler4

// This script is in a button named “Check Files” and calls the UserHandler4 handler in “Routines”
Variable Global g_theErrSound, g_theErrMessage, g_theErrLog
g_theErrSound = "Indigo"
g_theErrLog = (FindFolder "desk") & "Sample Error Log"
// Check to see if Drag and Drop is available. If not, call our error routine -- UserHanlder4.
If NOT (Gestalt "drag", 0)
     g_theErrMessage = "Drag and Drop isn't available!"
     Call UserHandler4, "Routines"
End If 
// Check to see if the file "Rosario" exists on the desktop. If not, call our error routine.
If NOT File((FindFolder "desk") & "Rosario").Exists
     g_theErrMessage = "Can’t find the Rosario file!"
     Call UserHandler4, "Routines"
End If 

See Also
Call command, Calling scripts as subroutines (page 125), Calling scripts as functions (page 125)